/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package webshop;

/**
 * @date Oct 29, 2011
 * @author Niko
 */

import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.TypedQuery;

@Stateless
public class webshopManager 
{
    @PersistenceContext(unitName = "webshopPU")
    private EntityManager em;
    
    public Klant createKlant(Klant k)
    {
        em.persist(k);
        return k;
    }
    
    public Klant updateKlant(Klant k)
    {
        return em.merge(k);
    }
    
    public void deleteKlant(Klant k)
    {
        em.remove(em.merge(k));
    }
    
    public List<Klant> findAllClients()
    {
        TypedQuery<Klant> q = em.createNamedQuery("findAllClients", Klant.class);
        return q.getResultList();
    }
    
    public List<Klant> findClientsByName(String achternaam, String voornaam)
    {
        TypedQuery<Klant> q = em.createNamedQuery("findClientsByName", Klant.class);
        q.setParameter("achternaam", achternaam);
        q.setParameter("voornaam", voornaam);
        return q.getResultList();
    }
}
